package com.ruoyi.framework.config;

import com.ruoyi.project.WxMoudle.Bases.WeixinConfig;
import com.ruoyi.project.sdk.IWXPayDomain;
import com.ruoyi.project.sdk.WXPayConfig;
import com.ruoyi.project.sdk.WXPayDomainSimpleImpl;
import org.springframework.context.annotation.Configuration;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

@Configuration
public class MyConfig extends WXPayConfig {

    private byte[] certData;

    public MyConfig() throws Exception {

        //不是沙箱环境要要下载证书，开出来

       /*String certPath = "/path/to/apiclient_cert.p12";

       File file = new File(certPath);

       InputStream certStream = new FileInputStream(file);

       this.certData = new byte[(int) file.length()];

       certStream.read(this.certData);

       certStream.close();*/

    }

    @Override
    public String getAppID() {
        return WeixinConfig.APPID;
    }

    @Override
    public String getMchID() {
        return WeixinConfig.MACHINEDID;
    }

    @Override
    public String getKey() {
        return WeixinConfig.PAYKEY;
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
//        return null;
        return WXPayDomainSimpleImpl.instance();
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

}
